

//
//  CZRepost.swift
//  GZWeibo007
//
//  Created by 陈华 on 15/12/25.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class CZRepost: NSObject {
    
    //MARK: - 定义属性
    
    ///转发的微博信息
    var retweeted_status: CZStatus?
    
    ///微博作者的用户信息
    var user: CZUser?
    
    ///原始图片地址
    var original_pic: String?
    
    //MARK: - 方法
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    ///加载转发微博数据
    class func loadRepostStatusData(id: Int,status: String, finished: (result:CZRepost?, error: NSError?) ->()) {
        
        
        CZNetworkTool.sharedInstance.loadRepostData(id, status: status) { (result, error) -> () in
            if result == nil || error != nil {
                finished(result: nil, error: error)
            }
            
            let Repost = CZRepost(dict: result!)
            
            finished(result: Repost, error: nil)
            
        }
    }
    
    //<模型嵌套字典
    override func setValue(value: AnyObject?, forKey key: String) {
        super.setValue(value, forKey: key)
        
        if key == "user" {
          let dict = value as! [String: AnyObject]
          user = CZUser(dict: dict)
            
        }else if key == "retweeted_status" {
            let dict = value as! [String: AnyObject]
            retweeted_status = CZStatus(dict: dict)
            
        }else {
            super.setValue(value, forKey: key)
        }
    }
    
}























